| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
catalogue.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef CATALOGUE_HPP
27#define CATALOGUE_HPP
28
29#include "../my_config.h"
30
31 extern "C"
32{
33#if HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36} // end extern "C"
37
38#include "infinint.hpp"
39#include "path.hpp"
40#include "integers.hpp"
41#include "mask.hpp"
42#include "user_interaction.hpp"
43#include "label.hpp"
44#include "escape.hpp"
45#include "datetime.hpp"
46#include "cat_entree.hpp"
47#include "cat_nomme.hpp"
48#include "cat_directory.hpp"
49#include "mem_ui.hpp"
50#include "delta_sig_block_size.hpp"
51
52 namespace libdar
53{
54
57
59 class catalogue: public mem_ui
60 {
61 public :
62 catalogue(const std::shared_ptr<user_interaction> & ui,
63 const datetime & root_last_modif,
64 const label & data_name);
65 catalogue(const std::shared_ptr<user_interaction> & ui,
66 const pile_descriptor & pdesc,
67 const archive_version & reading_ver,
68 compression default_algo,
69 bool lax,
70 const label & lax_layer1_data_name, // ignored unless in lax mode, in lax mode unless it is a cleared label, forces the catalogue label to be equal to the lax_layer1_data_name for it be considered a plain internal catalogue, even in case of corruption
71 bool only_detruit = false); // if set to true, only directories and detruit objects are read from the archive
72 catalogue(const catalogue & ref) : mem_ui(ref), out_compare(ref.out_compare), in_place(ref.in_place) { partial_copy_from(ref); };
73 catalogue(catalogue && ref) = delete;
74 catalogue & operator = (const catalogue &ref);
75 catalogue & operator = (catalogue && ref) = delete;
76 virtual ~catalogue() { detruire(); };
77
79
92 void set_early_memory_release() { early_mem_release = true; };
93
95 bool get_early_memory_release() const { return early_mem_release; };
96
98 bool get_memory_released() const { return mem_released; };
99
100 // reading methods. The reading is iterative and uses the current_read cat_directory pointer
101
102 virtual void reset_read() const; // set the reading cursor to the beginning of the catalogue
103 virtual void end_read() const; // set the reading cursor to the end of the catalogue
104 virtual void skip_read_to_parent_dir() const;
105 // skip all items of the current dir and of any subdir, the next call will return
106 // next item of the parent dir (no cat_eod to exit from the current dir !)
107 virtual bool read(const cat_entree * & ref) const;
108 // sequential read (generates cat_eod) and return false when all files have been read
109 virtual bool read_if_present(std::string *name, const cat_nomme * & ref) const;
110 // pseudo-sequential read (reading a directory still
111 // implies that following read are located in this subdirectory up to the next EOD) but
112 // it returns false if no entry of this name are present in the current directory
113 // a call with nullptr as first argument means to set the current dir the parent directory
114 void remove_read_entry(std::string & name);
115 // in the currently read directory, removes the entry which name is given in argument
116
118 virtual void remove_last_read();
119
120 const cat_directory & get_current_reading_dir() const { if(current_read == nullptr) throw SRC_BUG; return *current_read; };
121 // remove from the catalogue all the entries that have not yet been read
122 // by read().
123 virtual void tail_catalogue_to_current_read(bool including_last_read);
124
125 // return true if the last read entry has already been read
126 // and has not to be counted again. This is never the case for catalogue but may occur
127 // with escape_catalogue inherited class (where from the 'virtual').
128 // last this method gives a valid result only if the last read() entry is a directory as
129 // only directory may be read() twice.
130 virtual bool read_second_time_dir() const { return false; };
131
132
133 // Additions methods. The addition is also iterative but uses its specific current_add directory pointer
134
135 void reset_add();
136
138 // real implementation is only needed in escape_catalogue class, here there nothing to be done
139 virtual void pre_add(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
140 virtual void pre_add_ea(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
141 virtual void pre_add_crc(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
142 virtual void pre_add_dirty( const pile_descriptor* dest = nullptr) const {};
143 virtual void pre_add_ea_crc(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
144 virtual void pre_add_waste_mark(const pile_descriptor* dest = nullptr) const {};
145 virtual void pre_add_failed_mark(const pile_descriptor* dest = nullptr) const {};
146 virtual void pre_add_fsa(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
147 virtual void pre_add_fsa_crc(const cat_entree *ref, const pile_descriptor* dest = nullptr) const {};
148 virtual void pre_add_delta_sig(const pile_descriptor* dest = nullptr) const {};
149 virtual escape *get_escape_layer() const { return faked_escape; };
150 virtual void drop_escape_layer() { faked_escape = nullptr; };
151 virtual void set_escape_layer(escape* ptr) { faked_escape = ptr; };
152
153 void add(cat_entree *ref, bool addtostats = true); // add at end of catalogue (sequential point of view)
154 void re_add_in(const std::string &subdirname); // return into an already existing subdirectory for further addition
155 void re_add_in_replace(const cat_directory &dir); // same as re_add_in but also set the properties of the existing directory to those of the given argument
156 void add_in_current_read(cat_nomme *ref); // add in currently read directory
157 const cat_directory & get_current_add_dir() const { if(current_add == nullptr) throw SRC_BUG; return *current_add; };
158 void remove_in_current_add(const std::string & name);
159
160
161 // Comparison methods. The comparision is here also iterative and uses its specific current_compare directory pointer
162
163 void reset_compare() const;
164 bool compare(const cat_entree * name, const cat_entree * & extracted) const;
165 // returns true if the ref exists, and gives it back in second argument as it is in the current catalogue.
166 // returns false is no entry of that nature exists in the catalogue (in the current directory)
167 // if ref is a directory, the operation is normaly relative to the directory itself, but
168 // such a call implies a chdir to that directory. thus, a call with an EOD is necessary to
169 // change to the parent directory.
170 // note :
171 // if a directory is not present, returns false, but records the inexistant subdirectory
172 // structure defined by the following calls to this routine, this to be able to know when
173 // the last available directory is back the current one when changing to parent directory,
174 // and then proceed with normal comparison of inode. In this laps of time, the call will
175 // always return false, while it temporarily stores the missing directory structure
176
177
178
179 // non-iterative methods:
180
181
183
185 infinint update_destroyed_with(const catalogue & ref);
186
187
189
193 void update_absent_with(const catalogue & ref, infinint aborting_next_etoile);
194
195
197 void drop_all_non_detruits();
198
200 void drop_all_ea_and_fsa() { contenu->remove_all_ea_and_fsa(); };
201
203
206 bool is_subset_of(const catalogue & ref) const;
207
209 void reset_dump() const;
210
212 void dump(const pile_descriptor & pdesc) const;
213
214 entree_stats get_stats() const { return stats; };
215
217 bool is_empty() const { if(contenu == nullptr) throw SRC_BUG; return contenu->is_empty(); };
218
219 const cat_directory *get_contenu() const { return contenu; }; // used by data_tree
220
221 const label & get_data_name() const { return ref_data_name; };
222 void set_data_name(const label & val) { ref_data_name = val; };
223
224 datetime get_root_dir_last_modif() const { return contenu->get_last_modif(); };
225
227 void launch_recursive_has_changed_update() const { contenu->recursive_has_changed_update(); };
228
230 void set_all_mirage_s_inode_wrote_field_to(bool val) const { const_cast<cat_directory *>(contenu)->set_all_mirage_s_inode_wrote_field_to(val); };
231
232 datetime get_root_mtime() const { return contenu->get_last_modif(); };
233
235 void reset_all();
236
237 void set_to_unsaved_data_and_FSA() { if(contenu == nullptr) throw SRC_BUG; contenu->recursively_set_to_unsaved_data_and_FSA(); };
238
240 void change_location(const pile_descriptor & pdesc);
241
243
251 void transfer_delta_signatures(const pile_descriptor & destination,
252 bool sequential_read,
253 bool build,
254 const mask & delta_mask,
255 const infinint & delta_sig_min_size,
256 const delta_sig_block_size & signature_block_size);
257
259 void drop_delta_signatures();
260
261
263 bool has_in_place() const { return in_place.is_absolute(); };
264
266
270 bool get_in_place(path & arg) const;
271
273 virtual void set_in_place(const path & arg);
274
276 virtual void clear_in_place();
277
278
279 protected:
280 entree_stats & access_stats() { return stats; };
281 void copy_detruits_from(const catalogue & ref); // needed for escape_catalogue implementation only.
282
283 const cat_eod * get_r_eod_address() const { return & r_eod; }; // cat_eod are never stored in the catalogue
284 // however it is sometimes required to return such a reference to a valid object
285 // owned by the catalogue.
286
287
290 void swap_stuff(catalogue & ref);
291
293 bool is_mem_released() const { return mem_released; };
294
296 void set_mem_released() { mem_released = true; };
297
298 private :
299 cat_directory *contenu;
300 mutable path out_compare;
301 mutable cat_directory *current_compare;
302 mutable cat_directory *current_add;
303 mutable cat_directory *current_read;
304 path *sub_tree;
305 mutable signed int sub_count;
306 entree_stats stats;
307 label ref_data_name;
308 path in_place;
309 bool early_mem_release;
310 mutable bool mem_released;
311 escape* faked_escape;
312
313 void partial_copy_from(const catalogue &ref);
314 void detruire();
315
316 static const cat_eod r_eod;
317 static const U_I CAT_CRC_SIZE;
318 };
319
320
321
323
324} // end of namespace
325
326#endif
cat_directory.hpp
class used to organize objects in tree in catalogue as like directories in a filesystem
cat_entree.hpp
base class for all object contained in a catalogue
cat_nomme.hpp
base class of all objects contained in a catalogue and that can be named
libdar::archive_version
class archive_version manages the version of the archive format
Definition archive_version.hpp:47
libdar::cat_directory
the cat_directory inode class
Definition cat_directory.hpp:52
libdar::cat_directory::recursive_has_changed_update
void recursive_has_changed_update() const
ask recursive update for the recursive_has_changed field
libdar::cat_directory::remove_all_ea_and_fsa
void remove_all_ea_and_fsa()
remove all EA and FSA recursively (those "full" get flagged "partial")
libdar::cat_directory::is_empty
bool is_empty() const
whether this cat_directory is empty or not
Definition cat_directory.hpp:152
libdar::cat_entree
the root class from all other inherite for any entry in the catalogue
Definition cat_entree.hpp:60
libdar::cat_eod
the End of Directory entry class
Definition cat_eod.hpp:46
libdar::cat_nomme
the base class for all entry that have a name
Definition cat_nomme.hpp:45
libdar::catalogue
the catalogue class which gather all objects contained in a give archive
Definition catalogue.hpp:60
libdar::catalogue::change_location
void change_location(const pile_descriptor &pdesc)
change location where to find EA, FSA and DATA for all the objects of the catalogue
libdar::catalogue::set_all_mirage_s_inode_wrote_field_to
void set_all_mirage_s_inode_wrote_field_to(bool val) const
recursive setting of mirage inode_wrote flag
Definition catalogue.hpp:230
libdar::catalogue::in_place
path in_place
path of the directory used for root of the backup (at the time of the backup)
Definition catalogue.hpp:308
libdar::catalogue::current_read
cat_directory * current_read
points to the directory where the next item will be read
Definition catalogue.hpp:303
libdar::catalogue::remove_in_current_add
void remove_in_current_add(const std::string &name)
remove entry of given name that was added
libdar::catalogue::reset_all
void reset_all()
reset all pointers to the root (a bit better than reset_add() + reset_read() + reset_compare() + rese...
libdar::catalogue::faked_escape
escape * faked_escape
used when reading an archive with the help of an isolated catalog to keep trace of the sequential rea...
Definition catalogue.hpp:311
libdar::catalogue::update_destroyed_with
infinint update_destroyed_with(const catalogue &ref)
add into "this" detruit object corresponding to object of ref absent in "this"
libdar::catalogue::is_subset_of
bool is_subset_of(const catalogue &ref) const
check whether all inode existing in the "this" and ref have the same attributes
libdar::catalogue::stats
entree_stats stats
statistics catalogue contents
Definition catalogue.hpp:306
libdar::catalogue::swap_stuff
void swap_stuff(catalogue &ref)
libdar::catalogue::set_early_memory_release
void set_early_memory_release()
reduce memory footprint releasing from memory catalogue parts
Definition catalogue.hpp:92
libdar::catalogue::drop_all_ea_and_fsa
void drop_all_ea_and_fsa()
remove all EA and FSA (they get flagged as "partial" if they had "full" status
Definition catalogue.hpp:200
libdar::catalogue::sub_tree
path * sub_tree
path to sub_tree
Definition catalogue.hpp:304
libdar::catalogue::pre_add
virtual void pre_add(const cat_entree *ref, const pile_descriptor *dest=nullptr) const
catalogue extension routines for escape sequence
Definition catalogue.hpp:139
libdar::catalogue::transfer_delta_signatures
void transfer_delta_signatures(const pile_descriptor &destination, bool sequential_read, bool build, const mask &delta_mask, const infinint &delta_sig_min_size, const delta_sig_block_size &signature_block_size)
copy delta signatures to the given stack and update the cat_file objects accordingly
libdar::catalogue::out_compare
path out_compare
stores the missing directory structure, when extracting
Definition catalogue.hpp:300
libdar::catalogue::is_empty
bool is_empty() const
whether the catalogue is empty or not
Definition catalogue.hpp:217
libdar::catalogue::mem_released
bool mem_released
wether the catalogue content has been released and the object is no more usable
Definition catalogue.hpp:310
libdar::catalogue::current_add
cat_directory * current_add
points to the directory where to add the next file with add_file;
Definition catalogue.hpp:302
libdar::catalogue::get_memory_released
bool get_memory_released() const
return true if the catalogue has been released from memory
Definition catalogue.hpp:98
libdar::catalogue::drop_delta_signatures
void drop_delta_signatures()
remove delta signature from the catalogue object as if they had never been calculated
libdar::catalogue::set_mem_released
void set_mem_released()
let inherited class tell when memory release has completed
Definition catalogue.hpp:296
libdar::catalogue::get_early_memory_release
bool get_early_memory_release() const
get early memory release status
Definition catalogue.hpp:95
libdar::catalogue::drop_all_non_detruits
void drop_all_non_detruits()
remove/destroy from "this" all objects that are neither directory nor detruit objects
libdar::catalogue::ref_data_name
label ref_data_name
name of the archive where is located the data
Definition catalogue.hpp:307
libdar::catalogue::has_in_place
bool has_in_place() const
returns whether an in-place path is stored in the catalogue
Definition catalogue.hpp:263
libdar::catalogue::early_mem_release
bool early_mem_release
whether to release memory as soon as possible
Definition catalogue.hpp:309
libdar::catalogue::update_absent_with
void update_absent_with(const catalogue &ref, infinint aborting_next_etoile)
copy from ref missing files in "this" and mark then as "not_saved" (no change since reference)
libdar::catalogue::contenu
cat_directory * contenu
catalogue contents
Definition catalogue.hpp:299
libdar::catalogue::clear_in_place
virtual void clear_in_place()
clear the in_place path
libdar::catalogue::is_mem_released
bool is_mem_released() const
provide to inherited class the access to the early mem release mode and fields
Definition catalogue.hpp:293
libdar::catalogue::remove_last_read
virtual void remove_last_read()
remove last read entry
libdar::catalogue::get_in_place
bool get_in_place(path &arg) const
get the in_place path when available
libdar::catalogue::set_in_place
virtual void set_in_place(const path &arg)
set the in_place path for recording in the archive
libdar::catalogue::launch_recursive_has_changed_update
void launch_recursive_has_changed_update() const
recursive evaluation of directories that have changed (make the cat_directory::get_recurisve_has_chan...
Definition catalogue.hpp:227
libdar::catalogue::r_eod
static const cat_eod r_eod
needed to return eod reference, without taking risk of saturating memory
Definition catalogue.hpp:316
libdar::catalogue::sub_count
signed int sub_count
count the depth in of read routine in the sub_tree
Definition catalogue.hpp:305
libdar::catalogue::current_compare
cat_directory * current_compare
points to the current directory when extracting
Definition catalogue.hpp:301
libdar::catalogue::dump
void dump(const pile_descriptor &pdesc) const
write down the whole catalogue to file
libdar::catalogue::reset_dump
void reset_dump() const
before dumping the catalogue, need to set all hardlinked inode they have not been saved once
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::label
manage label data structure used in archive slice headers
Definition label.hpp:43
libdar::mask
the generic class, parent of all masks
Definition mask.hpp:62
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition mem_ui.hpp:55
libdar::mem_ui::mem_ui
mem_ui(const std::shared_ptr< user_interaction > &dialog)
constructor
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition path.hpp:51
libdar::path::is_absolute
bool is_absolute() const
whether the path is absolute or relative
Definition path.hpp:104
datetime.hpp
this file contains the definition of class datetime that stores unix times in a portable way
delta_sig_block_size.hpp
structure used to define how to select block size for delta signature
escape.hpp
class escape definition, used for sequential reading of archives
libdar::compression
compression
the different compression algorithm available
Definition compression.hpp:46
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
integers.hpp
are defined here basic integer types that tend to be portable
label.hpp
define the datastructure "label" used to identify slice membership to an archive
mask.hpp
here lies a collection of mask classes
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
path.hpp
here is the definition of the path class
libdar::delta_sig_block_size
defines how to calculate delta signature block size based of file size to delta sign
Definition delta_sig_block_size.hpp:50
libdar::entree_stats
holds the statistics contents of a catalogue
Definition entree_stats.hpp:49
user_interaction.hpp
defines the interaction interface between libdar and users.